﻿using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YJKRevitWallModule.WallModule
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdEditWallThickness : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elems)
		{
			Transaction transaction = null;
			Result result2;
			try
			{
				if (cmdData == null)
				{
					throw new System.ArgumentNullException("commandData");
				}
				transaction = new Transaction(cmdData.Application.ActiveUIDocument.Document);
				transaction.Start("edit wall thickness");
				Result result = new WallThicknessEditer(cmdData).NewWallType(ref msg);
				if (result != Autodesk.Revit.UI.Result.Succeeded)
				{
					if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
					{
						transaction.RollBack();
					}
					result2 = result;
				}
				else
				{
					transaction.Commit();
					result2 = Autodesk.Revit.UI.Result.Succeeded;
				}
			}
			catch (Exception ex)
			{
				msg = ex.Message;
				if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
				{
					transaction.RollBack();
				}
				result2 = Autodesk.Revit.UI.Result.Failed;
			}
			return result2;
		}
	}
}
